package com.smartao.base.module;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.smartao.core.mvc.BaseAction;
@Controller
@Scope("prototype")
@Results({ @Result(name = "success", location="list.jsp"),
		@Result(name = "input", location="input.jsp"),
		@Result(name = "view", location="view.jsp")})
public class ModuleAction extends BaseAction{

	private static final long serialVersionUID = -6651369439049023448L;

	@Autowired
	private ModuleService moduleService;
	
	private Module module;
	
	private List<Module> modules;
	
	private String message;
	
	@Override
	public String execute(){
		modules = moduleService.findAll();
		return SUCCESS;
	}
	
	@Override
	public String input(){
		if(id!=null){
			module = moduleService.findOne(id);
		}
		else{
			module = new Module();
		}
		return INPUT;
	}
	
	public String update(){
		moduleService.save(module);
		message = "保存成功.";
		return execute();
	}
	
	public String view(){
		if(module==null){
			module = moduleService.findOne(id);
		}
		return "view";
	}
	
	public Module getModule() {
		return module;
	}
	public void setModule(Module module) {
		this.module = module;
	}
	public List<Module> getModules() {
		return modules;
	}
	public void setModules(List<Module> modules) {
		this.modules = modules;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
}
